const Mock = require("mockjs");

const data = Mock.mock({
  "list|100": [
    {
      "id|+1": 1,
      img: "@image(40x40,@color())", //商品信息图片
      title: "@ctitle(20,30)", //商品信息标题
      name: "@cname(2,3)", //用户名称
      "shopMark|1-5": 1, //商品评分
      "serverMark|1-5": 1, //服务评分
      pContent: "@cword(40,55)", //评价内容
      hContent: "@cword(5,10)", //回复内容
      time: '@DATETIME("yyyy-MM-dd HH:mm:ss")', //时间
    },
  ],
});

Mock.mock("/commentList", "post", (req) => {
  const { pageIndex, pageSize, keyword, shopInput } = JSON.parse(req.body);
  let newList = JSON.parse(JSON.stringify(data.list));
  if (keyword) {
    newList = newList.filter((item) => item.name.includes(keyword));
  }
  if (shopInput) {
    newList = newList.filter((item) => item.title.includes(shopInput));
  }
  if (pageIndex && pageSize) {
    newList = newList.slice((pageIndex - 1) * pageSize, pageIndex * pageSize);
  }

  return {
    code: 20000,
    data: newList,
    total: data.list.length,
  };
});
